(function() {
  "use strict";
  APP.Views.TileView = Backbone.View.extend({
    events : {
      'click a': 'gotoLink'
    },
    initialize: function(params) {
      this.application = params.application;
      this.$el.attr('data-url', this.application.url);
      this.$el.attr('data-id', this.application.id);
    },
    setLayout: function(userPulpit) {
      this.application.userPulpit = userPulpit;
      this.render()
    },
    gotoLink: function(e) {
      e.preventDefault();
      window.open($(e.currentTarget).attr('href'), '_blank');
    },
    render: function() {
      this.$el.removeClass();
      this.$el.addClass('item');
      this.$el.addClass('layout-card');
      if (this.application.userPulpit !== null)
        this.$el.css('background-image', 'url(' + this.application.userPulpit.background + ')');
      if (this.application.userPulpit !== null) {
        switch(this.application.userPulpit.size) {
          case 1:
            this.$el.addClass('long');
            break;
          case 2:
            this.$el.addClass('vlong');
            break;
        }
      }
      this.$el.html(_.template($('#tileTemplate').html(), {
        app: this.application
      }));
      return this;
    }
  });
}());